<template>
  <div class="RoleAdmin">
    <a-card>
      <a-row>
        <a-col :span="8">
          <router-link to="/home/accessadmin/roleadd">
            <a-button type="primary" icon="plus">新建</a-button>
          </router-link>
        </a-col>
        <a-col :span="16" style="text-align:right">
          <a-input-search placeholder="请输入" style="width: 200px" v-model="inputSearch"/>
        </a-col>
      </a-row>
      <a-table
        style="margin-top:2%"
        :columns="columns"
        :dataSource="data"
        :pagination="pagination"
        @change="handleTableChange"
        :rowKey="record => record.authorityId"
      >
        <template slot="status" slot-scope="text,record">
          <a-switch checkedChildren="开" unCheckedChildren="关" :defaultChecked="record.status"/>
        </template>
        <template slot="operate" slot-scope="text,record">
          <a href="javascript:;" @click="editInfo(text,record)">编辑</a>
          <a-divider type="vertical"/>
          <a href="javascript:;" @click="delModal(text,record)">删除</a>
        </template>
      </a-table>
    </a-card>
  </div>
</template>

<script>
const columns = [
  {
    title: "名称",
    dataIndex: "designation",
    scopedSlots: { customRender: "name" },
    align: "center"
  },
  {
    title: "状态",
    dataIndex: "status",
    scopedSlots: { customRender: "status" },
    align: "center"
  },
  {
    title: "创建时间",
    dataIndex: "createTime",
    scopedSlots: { customRender: "latelyTime" },
    align: "center"
  },
  {
    title: "操作",
    dataIndex: "",
    scopedSlots: { customRender: "operate" },
    align: "center"
  }
];
const data = [
  {
    key: "1",
    userName: "1234",
    name: "口水娃玉米味烤肠袋装50g",
    phone: "",
    userRole: "1",
    status: "",
    latelyTime: "",
    operate: ["编辑", "上架"]
  }
];
export default {
  name: "RoleAdmin",
  data() {
    return {
      columns,
      data: [],
      pagination: {
        showSizeChanger: true,
        showQuickJumper: true,
        pageSizeOptions: ["2", "4", "8", "10", "12"],
        showTotal: (total, range) => {
          return `${range[0]}-${range[1]} 共${total}条`;
        },
        pageSize: 8, //每页条数
        defaultCurrent: 1, //默认当前页
        current: 1, //当前页
        total: 500 //数据总条数
      },
      inputSearch: ""
    };
  },
  methods: {
    handleTableChange(pagination, filters, sorter) {
      const pager = { ...this.pagination };
      pager.current = pagination.current;
      pager.pageSize = pagination.pageSize;
      pager.total = pagination.total;
      this.pagination = pager;
      this.search();
    },
    // 返回管理人员列表数据
    search() {
      this.axios
        .post(this.baseUrl + "/authority/search", {
          loginToken: this.$store.state.loginToken,
          pageNum: this.pagination.current,
          pageSize: this.pagination.pageSize,
          designation: this.inputSearch,
          sortType: 1
        })
        .then(response => {
          // console.log(response);
          this.data = response.data.data.list;
          this.pagination.total = response.data.data.total;
          this.pagination.pageSize = response.data.data.pageSize;
          this.pagination.current = response.data.data.pageNum;
        });
    }

    // // 编辑商品跳页传ID
    // editInfo(id) {
    //   var editId = id;
    //   this.$store.commit("editId", editId);
    //   this.$router.push({
    //     path: "/home/goodsadmin/allgoods/allgoodsedit"
    //   });
    // },
  },
  created() {
    this.search();
  },
  mounted() {}
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.RoleAdmin {
  width: 100%;
}
</style>
